<template>
	<view class="container">
		<view class="nav-bar">
			<view class="mav-bar-left" @click="goblak">
				<u-icon name="arrow-leftward" label="消息" size="23" space="15" labelSize="18"></u-icon>
			</view>
			<view class="nav-bar-right">
				<u-icon name="search" size="30"></u-icon>
			</view>
		</view>
		<!-- 头部卡片 -->
		<view class="header">
			<view class="header-content" v-for="item in headerDate" :key="item.name">
				<view class="header-content-item" :style="{backgroundColor:item.bgc}">
					<u-icon size="40" :name="item.icon" color="white"></u-icon>
				</view>
				<text>{{item.name}}</text>
			</view>
		</view>

		<!-- 主题内容区域 -->
		<view class="content">
			<view class="content-item" v-for="(item,index) in msg" :key="index" @click="gotoMsg(item)">
				<!-- 用户头像 -->
				<view class="content-item-userHeaderimg">
					<u-image width="110rpx" height="110rpx" :src="item.fromUser.avatarUrl" shape="circle"></u-image>
				</view>
				<view class="content-item-right">
					<view class="content-item-right-info">
						<text>{{item.fromUser.nickname}}</text>
						<text>{{$u.timeFrom(item.lastMsgTime)}}</text>
					</view>
					<!-- 消息内容 -->
					<view class="content-item-right-message">
						<view class="readMessag"> {{item.lastMsg | setMsg}}</view>
						<!-- 未读的信息数量 -->
						<view class="noReadMessage" v-if="item.newMsgCount !== 0">{{item.newMsgCount}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		_getPrivate
	} from '@/http/mine.js'
	export default {
		data() {
			return {
				headerDate: [{
						bgc: "#ff2255",
						name: "粉丝",
						icon: "account-fill"
					},
					{
						bgc: "#4DB8EB",
						name: "评论",
						icon: 'chat'
					},
					{
						bgc: "#ff6448",
						name: "@我",
						icon: 'heart'
					},
					{
						bgc: "#ffb812",
						name: "通知",
						icon: 'bell'
					}

				],
				limit: 30, //默认获取私信数量
				msg: [],
				currentpage: 1, //当前页数
				PageCount: 30, //每页条数
			};
		},

		methods: {
			async Private() {
				const {
					msgs: res
				} = await _getPrivate(this.limit)
				console.log(res);
				this.msg = res
				console.log(this.msg);
			},
			// 回到首页
			goblak() {
				uni.navigateBack({
					data: 1
				})
			},
			//进入私信页面
			gotoMsg(item) {
				// this.$store.commit('getMessage', item)
				const data = JSON.stringify(item)
				uni.navigateTo({
					url: '/view/personal/personal?id=' + data
				})
			}
		},
		filters: {
			setMsg(v) {
				return JSON.parse(v).msg
			}
		},
		onLoad() {
			this.Private()
		},
	}
</script>

<style lang="scss" scoped>
	* {
		font-family: STXihei;
	}

	.nav-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 30rpx 30rpx;
		// padding-top: 30rpx;
		// position: absolute;

		&-left {
			// text-align: left;
			// margin-left: 150rpx;
		}

		&-right {
			// text-align: right;
			// border: 1px solid red;
		}
	}

	.content {
		width: 100%;
		margin-top: 60rpx;

		&-item {
			display: flex;
			padding: 30rpx;

			&-right {
				width: 100%;
				padding-left: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;

				&-info {
					font-size: 28rpx;
					display: flex;
					justify-content: space-between;

				}

				&-message {
					color: #A0A0A0;
					font-size: 16rpx;
					display: flex;
					overflow: hidden;
					justify-content: space-between;

					.readMessag {
						width: 90%;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;
					}

					.noReadMessage {
						background-color: red;
						border-radius: 50%;
						text-align: center;
						line-height: auto;
						color: white;
						min-width: 35rpx;
					}
				}
			}
		}


	}


	.header {
		display: flex;
		// margin-top: 50rpx;
		width: 100%;

		&-content {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			&-item {
				border-radius: 50%;
				width: 110rpx;
				height: 110rpx;
				display: flex;
				align-items: center;
				justify-content: center;

			}

			text {
				font-size: 16rpx;
				margin-top: 10rpx;
			}

		}
	}
</style>
